package interfaces.tips;

import org.fenggui.Container;
import org.fenggui.binding.render.ImageFont;
import org.fenggui.event.ButtonPressedEvent;
import org.fenggui.event.IButtonPressedListener;

import settings.ControlSettings;

import fileHandling.language.LanguageLoader;
import fileHandling.language.options.Controls;
import interfaces.GUISource;
import interfaces.superWidgets.InterfaceButton;

public class DefaultKeyTipWindow extends TipWindow {
	
	private KeyTipContent kvContent;
	
	public DefaultKeyTipWindow(int width, int height) {
		super(width, height);
		
		init();
		
		layout();
	}
	
	private void addKeyValue(Controls c) {
		String key = LanguageLoader.get(c);
		String value = ControlSettings.get().getValueOf(c);
		kvContent.addLine(key, value);
	}
	
	@Override
	protected void init() {
		removeAllWidgets();
		
		ImageFont font = GUISource.smallFont;
		
		kvContent = new KeyTipContent(getWidth(), getHeight(), font);
		addWidget(kvContent);
		
		addKeyValue(Controls.Forward);
		addKeyValue(Controls.Break);
		addKeyValue(Controls.Left);
		addKeyValue(Controls.Right);
		addKeyValue(Controls.Nearest_Target);
		addKeyValue(Controls.Spawn_Menu);
		addKeyValue(Controls.Use_Counter_Measures);
		
		String key = LanguageLoader.get(Controls.Fire_Energy_Weapons);
		String value = "";
		kvContent.addLine(key, value);
		
		key = "";
		value = LanguageLoader.get(ControlSettings.get().getFireEnergyWeapons());
		kvContent.addLine(key, value);
		
		key = LanguageLoader.get(Controls.Look_Around);
		value = "";
		kvContent.addLine(key, value);
		
		key = "";
		value = LanguageLoader.get(ControlSettings.get().getLookAround());
		kvContent.addLine(key, value);
		
		InterfaceButton b = new InterfaceButton(font);
		b.getAppearance().removeAll();
		b.setSize(getWidth(), getHeight());
		b.addButtonPressedListener(new IButtonPressedListener() {
			@Override
			public void buttonPressed(ButtonPressedEvent e) {
				((Container)getParent()).removeWidget(DefaultKeyTipWindow.this);
			}
		});
		addWidget(b);
	}
}